pipeline {
    agent {
        kubernetes {
            cloud 'kubernetes'
            inheritFrom 'openjdk21'
        }
    }
    environment {
         DOCKER_ACCOUNT = credentials('Dockerhub-Account')
    }
    stages {
        stage("Git Pull") {
            steps {
                // git 组件识别不了environment中的值,算是个bug
                git credentialsId: 'Gitee-Account', url: 'https://gitee.com/cicd_3/demo_code.git'
            }
        }
        stage('Package') {
            steps {
                sh 'mvn clean package -Dmaven.test.skip=true'
            }
        }
        stage('showinfo') {
            steps {
                sh 'ls -ls'
            }
        }
        stage('Build Image') {
            steps {
                container('docker-build') {
                    sh 'docker --version'
                    sh 'ls -ls'

                    sh 'docker build -t qiujun623/demo_code:v1 -f Dockerfile .'
                    sh 'docker login -u $DOCKER_ACCOUNT_USR -p $DOCKER_ACCOUNT_PSW'
                    sh 'docker push qiujun623/demo_code:v1'
                }
            }
        }
    }
}